package com.bh.web.controller.base;

import com.bh.base.domain.BhUserScore;
import com.bh.base.service.IBhUserScoreService;
import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 员工积分Controller
 * 
 * @author slx
 * @date 2023-07-15
 */
@RestController
@RequestMapping("/base/score")
public class BhUserScoreController extends BaseController
{
    @Autowired
    private IBhUserScoreService bhUserScoreService;

    /**
     * 查询员工积分列表
     */
    @ApiOperation("查询员工积分列表")
    @PreAuthorize("@ss.hasPermi('base:score:list')")
    @GetMapping("/list")
    public TableDataInfo list(BhUserScore bhUserScore)
    {
        startPage();
        List<BhUserScore> list = bhUserScoreService.selectBhUserScoreList(bhUserScore);
        return getDataTable(list);
    }

    /**
     * 导出员工积分列表
     */
    @PreAuthorize("@ss.hasPermi('base:score:export')")
    @Log(title = "员工积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BhUserScore bhUserScore)
    {
        List<BhUserScore> list = bhUserScoreService.selectBhUserScoreList(bhUserScore);
        ExcelUtil<BhUserScore> util = new ExcelUtil<BhUserScore>(BhUserScore.class);
        util.exportExcel(response, list, "员工积分数据");
    }

    /**
     * 获取员工积分详细信息
     */
    @ApiOperation("获取员工积分详细信息")
    @PreAuthorize("@ss.hasPermi('base:score:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bhUserScoreService.selectBhUserScoreById(id));
    }

    /**
     * 新增员工积分
     */
    @ApiOperation("新增员工积分")
    @PreAuthorize("@ss.hasPermi('base:score:add')")
    @Log(title = "员工积分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BhUserScore bhUserScore)
    {
        return toAjax(bhUserScoreService.insertBhUserScore(bhUserScore));
    }

    /**
     * 修改员工积分
     */
    @ApiOperation("修改员工积分")
    @PreAuthorize("@ss.hasPermi('base:score:edit')")
    @Log(title = "员工积分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BhUserScore bhUserScore)
    {
        return toAjax(bhUserScoreService.updateBhUserScore(bhUserScore));
    }

    /**
     * 删除员工积分
     */
    @ApiOperation("删除员工积分")
    @PreAuthorize("@ss.hasPermi('base:score:remove')")
    @Log(title = "员工积分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bhUserScoreService.deleteBhUserScoreByIds(ids));
    }
}
